package com.kancy.spring.aop;

/**
 * 实现类包含了切面逻辑，如上面的 logMethodInvocation
 * @author kancy
 */
public interface MethodInvocation {

    /**
     * 调用之前
     * @param joinPoint
     * @throws Throwable
     */
    default void before(JoinPoint joinPoint) throws Throwable {
        before();
    }

    default void before(){}

    /**
     * 调用
     * @param joinPoint
     * @return
     * @throws Throwable
     */
    default Object invoke(JoinPoint joinPoint) throws Throwable {
        return joinPoint.proceed();
    }

    /**
     * 调用之后
     * @param joinPoint
     * @throws Throwable
     */
    default void after(JoinPoint joinPoint) throws Throwable {
        after();
    }

    default void after(){}

    /**
     * 方法执行异常之后
     * @param joinPoint
     * @throws Throwable
     */
    default void afterThrowing(JoinPoint joinPoint) throws Throwable {
        afterThrowing();
    }

    default void afterThrowing(){}

    /**
     * 调成完成返回时
     * @param joinPoint
     * @throws Throwable
     */
    default void afterReturning(JoinPoint joinPoint) throws Throwable {
        afterReturning();
    }

    default void afterReturning(){}

}
